<?php
/*
 Plugin Name: GOW7 Registration Plugin
 Plugin URI: http://johnpeng.net
 Description: Facilitates confrence registrations
 Version: 1.2
 Author: John Peng, 
 Edited: JCC
 Author URI: johnpeng.net
 */

$gow7_plugin_base = plugins_url( '/',__FILE__);
$mate_js_dir = $gow7_plugin_base . 'mate/js/';

add_action('admin_init', 'gow7_admin_init');
add_action('admin_menu', 'gow7_admin_menu');

function gow7_admin_init()
{
	global $mate_js_dir;
	// register mate scripts
	wp_register_script('mate_proto', $mate_js_dir . 'prototype.js');
	wp_register_script('mate_lang', $mate_js_dir . 'lang/lang_vars-en.js');
	wp_register_script('ajax_table', $mate_js_dir . 'ajax_table_editor.js');
	wp_register_script('mate_calendar', $mate_js_dir . 'jscalendar/calendar.js');
	wp_register_script('mate_calendar_lang', $mate_js_dir . 'jscalendar/lang/calendar-en.js');
	wp_register_script('mate_calendar_setup', $mate_js_dir . 'jscalendar/calendar-setup.js');
}

/* Currently the menus are hidden for development. Uncomment the original permissions and remove the current ones to activate for everyone */
function gow7_admin_menu()
{
	/* Register our plugin page */
	$reg_menu =	add_menu_page('GOW Registration 7','GOW 7', 'read'  /* 'edit_published_posts'*/, 'gow7_reg_page', 'gow7_reg_page');
	$coord_menu = add_submenu_page('gow7_reg_page', 'Coordinator Access', 'Coordinator', 'edit_posts'   /*'edit_published_posts'*/, 'gow7_coord_page', 'gow7_coord_page'); 
	$admin_menu = add_submenu_page('gow7_reg_page', 'Administrator Access', 'Administrator', 'edit_published_posts', 'gow7_admin_page', 'gow7_admin_page'); 
	add_submenu_page('gow7_reg_page', 'Conference Statistics', 'Statistics', 'edit_published_posts', 'gow7_stat_page', 'gow7_stat_page'); 
	$localities_menu = add_submenu_page('gow7_reg_page', 'Localities and Districts', 'Districts', 'edit_published_posts', 'gow7_districts_page', 'gow7_districts_page');
	add_submenu_page('gow7_reg_page', 'Emails', 'Emails', 'edit_published_posts', 'gow7_email_page', 'gow7_email_page');
	
	/* Using registered $page handle to hook script load */
	add_action('admin_print_scripts-' . $reg_menu, 'gow7_admin_styles');
	add_action('admin_print_scripts-' . $coord_menu, 'gow7_admin_styles');
	add_action('admin_print_scripts-' . $admin_menu, 'gow7_admin_styles');
	add_action('admin_print_scripts-' . $localities_menu, 'gow7_admin_styles');
}

function gow7_admin_styles()
{
	global $gow7_plugin_base;
	global $mate_js_dir;
	/*
	 * It will be called only on your plugin admin page, enqueue our script here
	 */
	echo '<link href="' . $gow7_plugin_base . 'mate/css/table_styles.css" rel="stylesheet" type="text/css" />' . "\n";
	echo '<link href="' . $gow7_plugin_base . 'mate/css/icon_styles.css" rel="stylesheet" type="text/css" />' . "\n";

	wp_enqueue_script('scriptaculous');
	wp_enqueue_script('mate_proto');
	wp_enqueue_script('mate_lang');
	wp_enqueue_script('ajax_table');

	echo '<link rel="stylesheet" type="text/css" media="all" href="' . $mate_js_dir . 'jscalendar/skins/aqua/theme.css" title="win2k-cold-1" />' . "\n";
	wp_enqueue_script('mate_calendar');
	wp_enqueue_script('mate_calendar_lang');
	wp_enqueue_script('mate_calendar_setup');
}

function gow7_disable_reg_page() {
	?>
	<div class="icon32" id="icon-themes"><br/></div>
	<h2>GOW Training Registraiton</h2>
	<br/>
	<p>Registration is now closed. You can only view your registrations.</p>
	<br/>
	<?php
	global $gow7_plugin_base;
	gow7_table_html($gow7_plugin_base . 'reg_ajax.php');
}

function gow7_reg_page() {
	global $gow7_plugin_base;
	?>
	<style type="text/css">
	.reg-heading {
		padding: 7px 9px;
		margin: 0;
		}
	.infoTable {
		margin: 3px;
		border: 1px solid;
		}
	.infoTable td, th{
		border: 1px solid;
		}
	/*
	.reg-text li {
		line-height: 1.4em;
		font-size: 1.2em;
		}
	*/
	</style>
	
	<div class="wrap reg-text">
	
	<div class="icon32" id="icon-themes"><br/></div>
	<h2>GOW Training Registration</h2>
	<br/>
	
	<div>
	
	<div class="postbox" style="width: 48%; float:left;">
	<h3 class="dashboard-widget-title reg-heading">Instructions</h3>
	<div style="padding: 1em;">
	<ul class="ul-square">
	<li>Each row represents a registration. Press the add button to add a registration.</li>
	<li>Typically you would register for yourself, your family, and those that are not so familiar with the internet.</li>
	<li>You will become the point of contact for those whom you register.</li>
	<li>You can log back in to change your registations until the cut off date.</li>
	<li>There are two types of registration: <i>3 day full-time</i>, <i>3 day part time</i>, and <i>Monthly only</i>. If you sign up for the 3 day training (full time or part time), you will also be automatically registered in the monthly training. Those registered for the monthly training may attend the evening sessions of the 3-day training. This may not be practical, however, since the 3-day training is held in a remote location in the Santa Cruz mountains.</li>
	<li><b>The 3-Day Training Full-Time</b>
		<ul class="ul-disc">
			<li>From Friday, Jan 4th (in the morning) to Lord's Day, Jan 6th (in the evening), 2013</li>
        	<li>At Redwood Christian Park, 15000 Two Bar Rd, Boulder Creek, CA 95006</li>
            <li>The cost varies from $160 to $200 per person depending on room type ($25 for registration fee included).
                <table class="infoTable">
                    <tr>
                        <th width="75px">Type</th>
                        <th width="200px">Description</th>
                        <th width="50px">Cost</th>
                    </tr>
                    <tr>
                        <th>Basic</th>
                        <td>Bunk bed w/ shared bath</td>
                        <td>$160</td>
                    </tr>                    
                    <tr>
                        <th>Moderate</th>
                        <td>Double room w/ shared bath</td>
                        <td>$180</td>
                    </tr>                    
                    <tr>
                        <th>Deluxe</th>
                        <td>Double room w/ private bath</td>
                        <td>$200</td>
                    </tr>
                </table>
            </li>
		</ul>
	</li>
	<li><b>The 3-Day Training Part-Time</b>
		<ul class="ul-disc">
			<li>For day time on Friday, Jan 4th, Saturday, Jan 5th, or Lord's Day, Jan 6th, 2013</li>
          	<li>NOTE: If you stay overnight (even just one night), you will be charged for fulltime registration. Transportation to and from the camp will be the responsibility of the trainee.</li>
            <li>Registration fee for the part-time trainings is $30 per day, plus $25 for registration.</li>
		</ul>
	</li>
	<li><b>The monthly training</b>
		<ul class="ul-disc">
			<li>One Saturday a month from 9:00 am to 12:00 pm (10:00 am to 1:00 pm in the Central Valley)</li>
          	<li>The dates are <b>Feb 16, Mar 23, Apr 20, May 18, and June 15,</b> 2013</li>
            <li>Registration fee for the monthly trainings is $25 per person.</li>
		</ul>
	</li>
		
	<li>There are pop-up help messages in each column header and input fields. Hold your mouse pointer over these areas to see the help messages.</li>
	
	<li>If you desire to purchase the training materials in a second language, please select a secondary language (There will be an additional cost):  English ($18.75), Spanish  ($18.75), Chinese  ($14.00)</li>
	
	</ul>
	</div>
	</div>
	
	<div class="postbox" style="width: 48%; float:right;">
	<h3 class="dashboard-widget-title reg-heading">Regulations</h3>
	<div style="padding: 1em;">
	<ul class="ul-square">
		<li>During the 6 month training, each trainee is expected to
    <ol>
      <li>Spend at least 30 minutes for morning revival by themselves daily; </li>
      <li>Study the lessons for at least 30 minutes by themselves daily; </li>
      <li>Meet with other trainees 90 minutes per week to practice the vital group, including review of the lessons;</li>
      <li>Attend the prayer meeting of the church; </li>
      <li>Prepare to prophesy in the Lord’s Day meeting of the church;</li>
      <li>Attend the monthly training meeting in the districts;</li>
      <li>Shepherd at least two seeking saints;</li>
      <li>Form a Bible study at home with new ones.</li>
    </ol></li>
	</ul>
	</div>
	</div>
	
	</div>
	
	<script type="text/javascript">
	function enableTable() {
		jQuery('#reg_table').show('slow');
		var targetOffset = jQuery("#reg_table").offset().top;
        jQuery('html,body').animate({scrollTop: targetOffset}, 500);
	}
	
	jQuery(document).ready( function() {
		    jQuery('.tooltips').tTips(); // tooltipize elements with classname "tooltip"
		});
		
	</script>
	
    
	<form style="clear: both; text-align: center">
	<p>Please agree with the above regulations before registering.</p>
	<input type="button" class="button-secondary" onclick="enableTable()" value="I AND THOSE WHOM I REGISTER UNDERSTAND AND AGREE WITH THE REGULATIONS"/>
	</form>
	<div id="reg_table" style="display: none;">
        <p>General Instructions for this term.</p>
        <ul class="ul-square">
            <li>If you are registering for the 3-day full time training, please make sure to select the accomodation. </li>
            <li>If you have special needs during the 3-day training, please fill in the box at the bottom of the form.</li>
            <li>In case you are new to the training, or need another copy of the binder, please use the "Binder" drop-down to select the language you need.</li>
        </ul>
        
	<?php
	gow7_table_html($gow7_plugin_base . 'reg_ajax.php');
	?>
	</div>
	</div>
	<?php
}

function gow7_coord_page() {
	?>
	<div class="icon32" id="icon-themes"><br/></div>
	<h2>Coordinator View</h2>
	<br/>
	<p>As the coordinator you can access all registrations from your locality.</p>
	<br/>
    <p>General Instructions for this term.</p>
    <ul class="ul-square">
        <li>If you are registering for the 3-day full time training, please make sure to select the accomodation. </li>
        <li>If you have special needs during the 3-day training, please fill in the box at the bottom of the form.</li>
        <li>In case you are new to the training, or need another copy of the binder, please use the "Binder" drop-down to select the language you need.</li>
    </ul>
	<?php
	global $gow7_plugin_base;
	gow7_table_html($gow7_plugin_base . 'coord_ajax.php');	
}

function gow7_admin_page() {
	?>
	<div class="icon32" id="icon-themes"><br/></div>
	<h2>Administrator View</h2>
	<br/>
	<p>As the administrator you can add, edit, and delete any registrations.</p>
	<br/>
    <p>General Instructions for this term.</p>
    <ul class="ul-square">
        <li>If you are registering for the 3-day full time training, please make sure to select the accomodation. </li>
        <li>If you have special needs during the 3-day training, please fill in the box at the bottom of the form.</li>
        <li>In case you are new to the training, or need another copy of the binder, please use the "Binder" drop-down to select the language you need.</li>
    </ul>
	<?php
	global $gow7_plugin_base;
	gow7_table_html($gow7_plugin_base . 'admin_ajax.php');
}

function gow7_stat_page() {
	?>
	<div class="icon32" id="icon-themes"><br/></div>
	<h2>Statistics</h2>
	<br/>
	<?php
	// Queries
	global $wpdb;
	
	/* Old statistics
	$reg_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(reg_type) FROM registrations7;"));
	$five_day = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM registrations7 WHERE reg_type = '5 day';"));
	$monthly = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM registrations7 WHERE reg_type = 'monthly';"));
	$incomplete_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(1) FROM registrations7 where reg_type IS NULL;"));
	*/
	
	$reg_types = $wpdb->get_results("SELECT reg_type, count(*) as count FROM registrations7 GROUP BY reg_type");
	
	// $five_day_rooms = $wpdb->get_results("SELECT COUNT(*) AS count, 5day_room AS room FROM registrations7 WHERE reg_type='5 day' OR length(5day_room) GROUP BY 5day_room;");
    
	$languages = $wpdb->get_results("SELECT COUNT(*) AS count, language FROM registrations7 WHERE reg_type IS NOT NULL GROUP BY language;");
	
	//$room_stat = $wpdb->get_results("SELECT city AS locality, reg_type, room_type AS room, COUNT(*) AS count FROM registrations7 LEFT JOIN localities ON registrations7.locality = localities.id WHERE reg_type = '3 day' OR length(room_type) GROUP BY city,room_type WITH ROLLUP");
	$room_stat = $wpdb->get_results("SELECT city AS locality, reg_type, room_type AS room, COUNT(*) AS count FROM registrations7 LEFT JOIN localities ON registrations7.locality = localities.id WHERE reg_type = '3 day full' GROUP BY city,room_type,reg_type" );

	$lang_stat = $wpdb->get_results(
		"SELECT city AS locality, language, COUNT(*) AS count FROM registrations7 " .
		"LEFT JOIN localities ON registrations7.locality = localities.id " .
		"GROUP BY city, language" );
	?>
	<style type="text/css">
	.statTable {
		margin: 10px;
		border: 1px solid;
		}
	.statTable td, th{
		border: 1px solid;
		}
	.pageTable td {
		vertical-align: top;
		}
	</style>
	
	<h2>General Statistics</h2>
	<table class="pageTable">
        <tr>
            <td>
	<?php 
	echo '<table class="statTable"><tr><th>Reg. Type</th><th>Count</th></tr>';
	foreach ($reg_types as $reg_type) {
		echo "<tr><td>$reg_type->reg_type</td><td>$reg_type->count</td></tr>";
	}
	echo "</table>";
	?>
	
            </td>
            <td>
	
	<?php
	echo '<table class="statTable"><tr><th>Language</th><th>Count</th></tr>';
	foreach ($languages as $language) {
		echo "<tr><td>$language->language</td><td>$language->count</td></tr>";
	}
	echo "</table>";
	
	$binder1 = $wpdb->get_results('SELECT count(*) as count, binder_lang, new FROM registrations7 where reg_type IS NOT NULL group by binder_lang, new');
	$binder2 = $wpdb->get_results('SELECT count(*) as count, binder2_lang, new FROM registrations7 where reg_type IS NOT NULL group by binder2_lang, new');

	echo '<table class="statTable"><tr><th>Binder#1 Language</th><th>Status</th><th>Count</th></tr>';
	foreach ($binder1 as $binder) {
		$new = ($binder->new)?"New":"Returning";
        if (($binder->new == 0) and ($binder->binder_lang == "None")) {
            echo "";
        } else {
            if ($binder->binder_lang == "None") {
                echo "<tr><td>Missing binder selection</td><td>$new</td><td>$binder->count</td></tr>";
            } else {
                echo "<tr><td>$binder->binder_lang</td><td>$new</td><td>$binder->count</td></tr>";
            }
        }
	}
	echo "</table>";
	
	echo '<table class="statTable"><tr><th>Binder#2 Language</th><th>Status</th><th>Count</th></tr>';
	foreach ($binder2 as $binder) {
		$new = ($binder->new)?"New":"Returning";
        if (($binder->new == 0) and ($binder->binder2_lang == "None")) {
            echo "";
        } else {
            if ($binder->binder2_lang == "None") {
                echo "<tr><td>Missing binder selection</td><td>$new</td><td>$binder->count</td></tr>";
            } else {
                echo "<tr><td>$binder->binder2_lang</td><td>$new</td><td>$binder->count</td></tr>";
            }
        }
	}
	echo "</table>";
	
	echo "</td></tr></table>";
	
    // district stats
	echo '<h2>Statistics by District</h2><table class="pageTable"><tr><td>';
	
	// district by locality
	$dist_loc_stat = $wpdb->get_results(
		"SELECT
			(SELECT districts.name FROM districts WHERE districts.id = registrations7.district) AS dis, 
			(SELECT localities.city FROM localities WHERE localities.id = registrations7.locality) AS loc, 
		COUNT(*) AS count
		FROM registrations7 WHERE reg_type IS NOT NULL
		GROUP BY dis, loc");
	echo '<table class="statTable"><tr><th>District</th><th>Locality</th><th>Count</th></tr>';
	foreach ($dist_loc_stat as $stat) {
		echo "<tr><th>$stat->dis</th><td>$stat->loc</td><td>$stat->count</td></tr>";
	}
	echo "</table>";
	
	echo '</td><td>';
	
	// removed districts by language since each district is one language now

	echo '</td></tr></table>';

// localities breakdown stats
	echo '<h2>Statistics by Locality</h2><table class="pageTable"><tr><td>';
	
	// localities by registration type
	$reg_stat = $wpdb->get_results(
		"SELECT city AS locality, reg_type AS registration, COUNT(*) AS count FROM registrations7 
		LEFT JOIN localities ON registrations7.locality = localities.id 
		GROUP BY city,reg_type");
	//echo '<table class="statTable"><tr><th>Locality</th><th>Registration Type</th><th>Count</th><th>Cost</th></tr>';
	echo '<table class="statTable"><tr><th>Locality</th><th>Registration Type</th><th>Count</th></tr>';
	foreach ($reg_stat as $stat) {
		//$cost = $stat->count * 25;
		//echo "<tr><th>$stat->locality</th><td>$stat->registration</td><td>$stat->count</td><td>\$$cost</td></tr>";
		echo "<tr><th>$stat->locality</th><td>$stat->registration</td><td>$stat->count</td></tr>";
	}
	echo "</table></td><td>";
    

	// localities by room type
	//echo '<table class="statTable"><tr><th>Locality</th><th>Room Type</th><th>Count</th><th>Cost</th></tr>';
	echo '<table class="statTable"><tr><th>Locality</th><th>Room Type</th><th>Count</th></tr>';
	$locality = '';
	$local_cost = 0;
	$total_cost = 0;
	foreach ($room_stat as $stat) {
		if( $locality != $stat->locality ) {
			$local_cost = 0;
			$locality = $stat->locality;
		}
		
        if ($stat->reg_type == "3 day full") {
            if ((is_null($stat->room)) or ($stat->room == "")) {
                echo "<tr><th>$stat->locality</th><td>None</td><td>$stat->count</td>";
            } else {
                echo "<tr><th>$stat->locality</th><td>$stat->room</td><td>$stat->count</td>";
            }
            /*
            if( $stat->room ) {
                switch ($stat->room) {
                    case 'basic':
                        $cost = 210 * $stat->count;
                        break;
                    case 'moderate':
                        $cost = 230 * $stat->count;
                        break;
                    case 'deluxe':
                        $cost = 270 * $stat->count;
                        break;
                }
                $local_cost += $cost;
                $total_cost += $cost;	
                echo "<td>\$$cost</td></tr>";
                
            } else if( $stat->locality ) {
                echo "<td>\$$local_cost</td></tr>";
            } else {
                echo "<td>\$$total_cost</td></tr>";
            }*/
        }
	}
	echo "</table></td><td>";

	
	// localities by language
	echo '<table class="statTable"><tr><th>Locality</th><th>Language</th><th>Count</th></tr>';
	foreach ($lang_stat as $stat) {
		//if(!$stat->locality) $stat->locality = 'total';
		//if(!$stat->room) $stat->room = 'total';
		echo "<tr><th>$stat->locality</th><td>$stat->language</td><td>$stat->count</td></tr>";
	}
	
	echo "</table></td></tr><tr><td>";	
    

    // localities by binder and registration type
	$binder1a = $wpdb->get_results('SELECT count(*) as count, binder_lang, new, city AS locality, reg_type AS registration FROM registrations7 LEFT JOIN localities ON registrations7.locality = localities.id WHERE reg_type IS NOT NULL GROUP BY binder_lang, new, city');
	$binder2a = $wpdb->get_results('SELECT count(*) as count, binder2_lang, new, city AS locality, reg_type AS registration FROM registrations7 LEFT JOIN localities ON registrations7.locality = localities.id WHERE reg_type IS NOT NULL GROUP BY binder2_lang, new, city');
    
	echo '<table class="statTable"><tr><th>Locality</th><th>Binder Language Requested</th><th>Count</th></tr>';
	foreach ($binder1a as $stat) {
        if (($stat->new == 0) and ($stat->binder_lang == "None")) {
            echo ""; //skipping the case where no binder was selected and returning trainee
        } else {
            if ($stat->binder_lang == "None") {
                // new trainee, but no binder selected
                echo "<tr><th>$stat->locality</th><td>Missing binder selection.</td><td>$stat->count</td></tr>";
            } else {
                // new trainee and binder selected
                echo "<tr><th>$stat->locality</th><td>$stat->binder_lang</td><td>$stat->count</td></tr>";
            }
        }
	}
	echo "</table></td><td>";	
    
    echo '<table class="statTable"><tr><th>Locality</th><th>Binder2 Language Requested</th><th>Count</th></tr>';
	foreach ($binder2a as $stat) {
        if ($stat->binder2_lang == "None") {
            echo "";
        } else {
            echo "<tr><th>$stat->locality</th><td>$stat->binder2_lang</td><td>$stat->count</td></tr>";
        }
	}
	echo "</table></td></tr></table>";

}

function gow7_districts_page() {
	?>
	<div class="icon32" id="icon-themes"><br/></div>
	<h2>Districts Configuration</h2>
	<br/>
	<?php
	global $gow7_plugin_base;
	gow7_table_html($gow7_plugin_base . 'districts_ajax.php');
}



function gow7_email_page() {

	function print_emails($emails) {
		foreach( $emails as $email) {
			print "\"$email->first $email->last\" <$email->email>, ";
		}
	}

	function display_emails($emails) {
		echo "<table class=\"emailTable\"><tr><th>Name</th><th>Locality</th><th>Email</th></tr>";
		foreach( $emails as $email ) {
			print "<tr><td>$email->first $email->last</td><td>$email->locality</th><td>$email->email</td></tr>";
		}
		echo "</table>";
	}
	
	global $wpdb;
	$admin_emails = $wpdb->get_results("
SELECT 
  (SELECT meta_value FROM wp_usermeta WHERE wp_usermeta.meta_key = 'first_name' AND wp_usermeta.user_id=wp_users.id) AS first, 
  (SELECT meta_value from wp_usermeta WHERE wp_usermeta.meta_key = 'last_name' AND wp_usermeta.user_id=wp_users.id) AS last,
  (SELECT city from localities where localities.id = 
    (SELECT meta_value FROM wp_usermeta WHERE wp_usermeta.meta_key = 'locality' AND wp_usermeta.user_id=wp_users.id)) AS locality,
  user_email AS email FROM wp_users 
  WHERE 
    wp_users.user_login NOT LIKE '%unverified%' AND 
    wp_users.ID in (SELECT user_id FROM wp_usermeta WHERE meta_key='wp_user_level' AND meta_value >= 2) ORDER by locality;");
	
	$coord_emails = $wpdb->get_results("
SELECT 
  (SELECT meta_value FROM wp_usermeta WHERE wp_usermeta.meta_key = 'first_name' AND wp_usermeta.user_id=wp_users.id) AS first, 
  (SELECT meta_value from wp_usermeta WHERE wp_usermeta.meta_key = 'last_name' AND wp_usermeta.user_id=wp_users.id) AS last,
  (SELECT city from localities where localities.id = 
    (SELECT meta_value FROM wp_usermeta WHERE wp_usermeta.meta_key = 'locality' AND wp_usermeta.user_id=wp_users.id)) AS locality,
  user_email as email FROM wp_users 
  WHERE 
    wp_users.user_login NOT LIKE '%unverified%' AND 
    wp_users.ID in (SELECT user_id FROM wp_usermeta WHERE meta_key='wp_user_level' AND meta_value >= 1) ORDER by locality;");		
	
	$all_emails = $wpdb->get_results("
SELECT 
  (SELECT meta_value FROM wp_usermeta WHERE wp_usermeta.meta_key = 'first_name' AND wp_usermeta.user_id=wp_users.id) AS first, 
  (SELECT meta_value from wp_usermeta WHERE wp_usermeta.meta_key = 'last_name' AND wp_usermeta.user_id=wp_users.id) AS last,
  (SELECT city from localities where localities.id = 
    (SELECT meta_value FROM wp_usermeta WHERE wp_usermeta.meta_key = 'locality' AND wp_usermeta.user_id=wp_users.id)) AS locality,
  user_email as email FROM wp_users 
  WHERE 
    wp_users.user_login NOT LIKE '%unverified%' ORDER BY locality;");		
	 
	?>
	<style type="text/css">
	.emailTable {
		margin: 10px;
		border: 1px solid;
		}
	.emailTable td, th{
		border: 1px solid;
		padding: 0em 2em;
		}
	</style>
	<div class="icon32" id="icon-themes"><br/></div>
	<h2>Emails</h2>
	<br/>
	<p><b>Administrator Emails</b></p>
	<?php display_emails($admin_emails); ?>
	<p>Copy from the box below and paste to your email client to email these saints.</p>
	<textarea rows="5" cols="100" onclick="this.focus();this.select()" readonly="readonly"><?php print_emails($admin_emails); ?></textarea>
	<br/>
	<p><b>Coordinator and Administrator Emails</b></p>
	<?php display_emails($coord_emails); ?>
	<p>Copy from the box below and paste to your email client to email these saints.</p>
	<textarea rows="5" cols="100" onclick="this.focus();this.select()" readonly="readonly"><?php print_emails($coord_emails); ?></textarea>
	<br/>
	<p><b>All Verified Emails</b></p>
	<?php display_emails($all_emails); ?>
	<p>Copy from the box below and paste to your email client to email these saints.</p>
	<textarea rows="5" cols="100" onclick="this.focus();this.select()" readonly="readonly"><?php print_emails($all_emails); ?></textarea>
	
	
	<?php
}

function gow7_table_html($ajaxUrl)
{
	global $gow7_plugin_base;
	?>
<div align="left" style="position: relative;">
<div id="ajaxLoader1"><img src="<?php echo $gow7_plugin_base?>mate/images/ajax_loader.gif" alt="Loading..." /></div>
</div>

<br />

<div id="historyButtonsLayer" align="left"></div>

<div id="historyContainer">
<div id="information"></div>

<div id="titleLayer"
	style="padding: 2px; font-weight: bold; font-size: 18px; text-align: center;">
</div>

<div id="tableLayer" align="center"></div>

<div id="recordLayer" align="center"></div>

<div id="searchButtonsLayer" align="center"></div>
</div>

<script type="text/javascript">
				trackHistory = false;
				var ajaxUrl = '<?php echo $ajaxUrl; ?>';
				toAjaxTableEditor('update_html','');
			</script>
<?php
}
?>
